<?php
namespace addons\mall\controller;
/**
 */
class Help extends Base
{
    public function _initialize() {
        parent::_initialize();
        $this->model = new \app\common\model\mall\oper\Help;
    }

    /**
     *	帮助中心
     */
    public function help(){
        //获取左侧列表
        $list = $this->model->helpList();
        //获取帮助内容
        $data = $this->model->getHelpById();

        $this->assign('data',$data);
        $this->assign('list',$list);

        //面包屑导航
        $bcNav = [];
        if(!empty($data)){
            $bcNav = $this->bcNav();
        }
        $this->assign('bcNav',$bcNav);
        return $this->fetch();
    }
    /**
     *  记录解决情况
     */
    public function recordSolve(){
        return $this->model->recordSolve();
    }
    /**
     * 面包屑导航
     */
    public function bcNav(){
        return $this->model->bcNav();
    }

    /**
	*	新闻列表
	*/
	public function index(){
		$pageObj = $this->model->nList();
		$news = collection($pageObj)->toArray();
		// 分页页码
		//$page = $pageObj->render();
		//$this->assign('page',$page);
		//获取左侧列表
		$leftList = $this->model->NewsList();
		$this->assign('list',$leftList);
		$this->assign('newsList',$news);
		$this->assign('catId',(int)input('catId'));
		//面包屑导航
		$bcNav = $this->bcNav();
		// 防止用户取出帮助中心分类
		foreach($bcNav as $k=>$v){
			if($v['id']==1){
				$bcNav = [];
				break;
			}
		}
		// 获取title
		$currTitle = '';
		foreach($bcNav as $k=>$v){
			if($v['id']==(int)input('catId'))$currTitle = $v['name'];
		}
		$this->assign('title',$currTitle);
		$this->assign('bcNav',$bcNav);
		// 防止没有数据时报错
		//if(empty($bcNav))$this->redirect('/addons/mall/help/index/');
		return $this->fetch();
	}

    /**
     *	新闻详情
     */
	public function detail(){
		//获取左侧列表
		$list = $this->model->NewsList();
		//当前分类id
		$content = $this->model->getNewsById();
		$this->assign('catId',(int)$content['cat_id']);
		$this->assign('list',$list);
		$this->assign('content',$content);


		//面包屑导航
		$bcNav = [];
		if(!empty($content)){
			$bcNav = $this->bcNav();
		}
		$this->assign('bcNav',$bcNav);


		if((int)input('id')==0){
			// 资讯列表下的新闻
			$pageObj = $this->model->getHelp();
			$news = collection($pageObj)->toArray();
			// 分页页码
			$page = $pageObj->render();
			$this->assign('page',$page);
			$this->assign('index',$news['Rows']);
		}
		return $this->fetch();
	}

}